﻿using System;
using System.Linq;
using System.Web.Mvc;

namespace CID.Web.Support.Ajax
{
    public sealed class AjaxViewResult : AjaxActionResult
    {
        public override string Type { get { return "View"; } }
        public string ModelError { get; set; }

        public AjaxViewResult(ViewResult viewResult)
        {
            ModelError = String.Join("\r\n", viewResult.ViewData.ModelState.Values.Where(x => (x.Errors.Count > 0)).Select(x => String.Join("\r\n", x.Errors.Select(y => y.ErrorMessage))));
        }
    }
}